<?php

namespace App\Http\Requests;

use App\Models\Bar;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreBarRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true; // 所有已登录用户都可以创建贴吧
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'name' => ['required', 'string', 'max:50', 'unique:'.Bar::class],
            'slug' => ['nullable', 'string', 'max:50', 'unique:'.Bar::class],
            'description' => ['nullable', 'string', 'max:500'],
            'avatar' => ['nullable', 'image', 'mimes:jpeg,png,jpg,gif', 'max:2048'],
        ];
    }

    /**
     * Get custom attributes for validator errors.
     */
    public function attributes(): array
    {
        return [
            'name' => '贴吧名称',
            'slug' => 'URL友好名称',
            'description' => '贴吧简介',
            'avatar' => '贴吧头像',
        ];
    }
}
